<?php

/*
 * Created by generator
 *
 */

/**
 * Recupere la liste des enregistrements
 * @param object $db database object
 * @return array of data
 */
if (!function_exists('getAllsaisonsFromDB')) {
	function getAllsaisonsFromDB($db) {
		$sql = "SELECT saiidsai, sailbnom, saidtdeb, saidtfin, sainbsem from gyasai order by saidtdeb asc";
		$query = $db->query($sql);

		// recuperer les enregistrements
		$records = array();
		foreach ($query->result_array() as $row) {
			$records[] = $row;
		}
		return $records;
	}
}


/**
 * Insere un nouvel enregistrement
 * @param object $db database object
 * @param string ...
 * @return number identifiant
 */
if (!function_exists('insertNewsaison')) {
	function insertNewsaison($db, $sailbnom, $saidtdeb, $saidtfin, $sainbsem) {
		$data=array( 'sailbnom'=>$sailbnom, 'saidtdeb'=>$saidtdeb, 'saidtfin'=>$saidtfin, 'sainbsem'=>$sainbsem);
		$db->insert('gyasai',$data);
		return $db->insert_id();
	}
}

/**
 * Mise a jour d'un enregistrement
 */
if (!function_exists('updatesaison')) {
	function updatesaison($db, $saiidsai, $sailbnom, $saidtdeb, $saidtfin, $sainbsem) {
		$sql = "update gyasai set sailbnom = ?, saidtdeb = ?, saidtfin = ?, sainbsem = ? where saiidsai=?";
		$query = $db->query($sql, array($sailbnom, $saidtdeb, $saidtfin, (int)sainbsem, (int)$saiidsai ));
	}
}


/**
 * Suppression d'un enregistrement
 */
if (!function_exists('deletesaison')) {
	function deletesaison($db, $saiidsai) {
		$sql = "delete from gyasai where saiidsai=?";
		$query = $db->query($sql, array((int)$saiidsai));
	}
}


/**
 * Recupere les informations d'un enregistrement
 * @param object $db database object
 * @param int id de l'enregistrement
 * @return array
 */
if (!function_exists('getsaisonRow')) {
	function getsaisonRow($db, $saiidsai) {
		$sql = "select saiidsai, sailbnom, saidtdeb, saidtfin, sainbsem from gyasai " .
		"where saiidsai=?";
		$query = $db->query($sql, array((int)$saiidsai));
		if ($query->num_rows() == 0) {
			return null;
		}
		return $query->row_array();
	}
}

	/***************************************************************************
	 * USER DEFINED FUNCTIONS
	 ***************************************************************************/

/**
 * Recupere la saison actuelle, sysdate comprise entre les dates de la saison
 * @param object $db database object
 * @param int id de l'enregistrement
 * @return array
 */
if (!function_exists('getCurrentSaisonRow')) {
	function getCurrentSaisonRow($db) {
		$sql = "select saiidsai, sailbnom, saidtdeb, saidtfin, sainbsem from gyasai " .
		"where sysdate() between saidtdeb and saidtfin";
		$query = $db->query($sql);
		if ($query->num_rows() == 0) {
			return null;
		}
		return $query->row_array();
	}
}


?>
